{% extends "base_generic.html" %}
{% block script %}
<script type="text/javascript">
    function CheckSong(title,artist) {
      var songurl = string_to_slug(title);
      var artisturl = string_to_slug(artist);
      
      $.post("/search/check/song", { songtitle: title, songurl: songurl, artistname: artist, artisturl: artisturl },
         function(data){
           if (data == 'OK'){
             var baseurl = window.location.host;
             window.location.href = 'http://' + baseurl +  "/" + artisturl + "/" + songurl;
           }
         });
      return false;
    }
    function CheckArtist(artist) {
      var artisturl = string_to_slug(artist);
      
      $.post("/search/check/artist", { artistname: artist, artisturl: artisturl },
         function(data){
           if (data == 'OK'){
             var baseurl = window.location.host;
             window.location.href = 'http://' + baseurl +  "/" + artisturl;
           }
         });
      return false;
    }
</script>
{% endblock %}
{% block content %}
<div id="maincontent">
  <h1>Search results</h1>


  {% if songs %}
    <h2>Songs</h2>
    {% for song in songs %}
      <ul class="song">
        <li><a href="#" onclick="CheckSong('{{ song.title }}', '{{ song.artist }}');">{{ song.title }} (<em>{{ song.artist }}</em>)</a></li>
      </ul>
    {% endfor %}
  {% endif %}


  {% if artists %}
    <h2>Artists</h2>
    {% for artist in artists %}
      {% if forloop.counter < 2 %}
        <ul class="artist">
          <li><a href="#" onclick="CheckArtist('{{ artist }}');">{{ artist }}</a></li>
        </ul>
      {% endif %}
      <ul class="artist">
        <li>{{ artist }}</li>
      </ul>
    {% endfor %}
  {% endif %}
  
  {% if albums %}
    <h2>Albums</h2>
    {% for album in albums %}
      <ul class="album">
        <li><a href="#" onclick="CheckSong('{{ album.0.title }}, {{ album.0.artist }}');"><img src="{{ album.1 }}" alt="" /> {{ album.0.title }} (<em>{{ album.0.artist }}</em>)</a></li>
      </ul>
    {% endfor %}
  {% endif %}

</div>
<div id="sidebar">

</div>
{% endblock %}
